﻿using SuperX.Common.Helper;
using SuperX.SuperSocket.Socket.Command;
using Newtonsoft.Json.Linq;
using System;
using System.Collections.Generic;

namespace SuperX.SuperSocket.Server.Command
{
    public class CommandManager
    {
        public static event EventHandler<MessageEventArgs> MessageReceived;

        internal static void FireMessageReceived(object sender, MessageEventArgs e)
        {
            MessageReceived?.Invoke(sender, e);
        }

        internal static Dictionary<string, string> ConvertHeaders(string header)
        {
            if (string.IsNullOrWhiteSpace(header)) return null;
            var jObj = JObject.Parse(header);
            var dic = jObj.ToObject(typeof(Dictionary<string, string>));
            return dic as Dictionary<string, string>;
        }

        internal static string Serialize(Dictionary<string, string> dic)
        {
            return JsonHelper.TransferObjectJsonSerialize(dic);
        }
    }
}